package com.sdry.web.controller.lz;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sdry.model.hpf.LineSideLibraryOut;
import com.sdry.model.lz.LzQueryCriteria;
import com.sdry.service.lz.LzProductTracingService;
import com.sdry.utils.ResponseUtil;

/**
 * 
 * @ClassName LzProductTracingController
 * @Description 产品追溯(按批次号查询)
 * @Author lz
 * @Date 2019年1月11日 09:34:04
 * @Version 1.0
 */
@Controller
@RequestMapping("/lzProductTracing")
public class LzProductTracingController {

	public static final Integer AFFECT_ROW = 0;
	@Resource
	LzProductTracingService lzProductTracingService;
	
	/**
	 * 根据批次号查询入库时间
	 * @param response
	 * @param batchNum 批次号
	 * @throws Exception
	 */
	@RequestMapping("/queryIndateByBatchNum")
	public void queryIndateByBatchNum(HttpServletResponse response, String batchNum) {
		List<LineSideLibraryOut> indateList = lzProductTracingService.queryIndateByBatchNum(batchNum);
		JSONObject jsonObject = new JSONObject();
        JSONArray jsonArray = JSONArray.fromObject(indateList);
        jsonObject.put("code", AFFECT_ROW);
        jsonObject.put("data", jsonArray);
        jsonObject.put("count", 0);
        try {
            ResponseUtil.write(response, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
	}
	
	/**
	 * 分页查询线边库出库
	 * @param response
	 * @param criteria
	 * @throws Exception
	 */
	@RequestMapping("/queryLineSideLibraryOut")
	public void queryLineSideLibraryOut(HttpServletResponse response, LzQueryCriteria criteria) {
		String keyword01 = criteria.getKeyword01();
        if(keyword01 == null){
            keyword01 = "";
        }
        criteria.setKeyword01(keyword01);
        List<LineSideLibraryOut> lineSideLibraryOutList = lzProductTracingService.queryLineSideLibraryOut(criteria);
        int count = lzProductTracingService.countLineSideLibraryOut(criteria);
        JSONObject jsonObject = new JSONObject();
        JSONArray jsonArray = JSONArray.fromObject(lineSideLibraryOutList);
        jsonObject.put("code", AFFECT_ROW);
        jsonObject.put("data", jsonArray);
        jsonObject.put("count", count);
        try {
            ResponseUtil.write(response, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
	
	/**
	 * 分页查询线边库出库
	 * @param response
	 * @param batchNum
	 * @throws Exception
	 */
	@RequestMapping("/queryLineSideLibraryOutByBatchNum")
	public void queryLineSideLibraryOutByBatchNum(HttpServletResponse response, String batchNum) {
        List<LineSideLibraryOut> lineSideLibraryOutList = lzProductTracingService.queryLineSideLibraryOutByBatchNum(batchNum);
        //int count = lzProductTracingService.countLineSideLibraryOutByBatchNum(criteria);
        JSONObject jsonObject = new JSONObject();
        JSONArray jsonArray = JSONArray.fromObject(lineSideLibraryOutList);
        jsonObject.put("code", AFFECT_ROW);
        jsonObject.put("data", jsonArray);
        jsonObject.put("count", 0);
        try {
            ResponseUtil.write(response, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
